import {
  MiddlewareConsumer,
  Module,
  NestModule,
  // RequestMethod,
} from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { CoffeesModule } from './coffees/coffees.module';
import { appFnMiddleware } from './common/middleware/app-middleware/app-fn.middleware';
import { AppMiddleware } from './common/middleware/app-middleware/app.middleware';
import { TasksModule } from './tasks/tasks.module';

@Module({
  imports: [CoffeesModule, TasksModule],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    console.log('AppModule init, configure in');
    consumer.apply(AppMiddleware, appFnMiddleware).forRoutes('*');

    // 复杂场景
    // consumer
    //   .apply(AppMiddleware)
    //   .exclude(
    //     { path: 'coffees', method: RequestMethod.GET },
    //     { path: 'coffees', method: RequestMethod.POST },
    //     'coffees/(.*)',
    //   )
    //   .forRoutes(AppController);

    // 多中间件
    // consumer.apply(cors(), helmet(), AppMiddleware).forRoutes(CatsController);
  }
}
